/*
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};
*/
class Solution {
public:
        using vi=vector<int>;
        using vvi=vector<vector<int>>;
        vector<vector<int> > Print(TreeNode* pRoot) {
            vi path;
            vvi ans;
            queue<TreeNode*> q;
            if(!pRoot) return ans;
            q.push(pRoot);
            int size, i;
            TreeNode* tmp;
            while(!q.empty()) {
                size = q.size();
                for(i = 0; i < size; i++) {
                    tmp = q.front();
                    q.pop();
                    path.push_back(tmp->val);
                    if(tmp->left) q.push(tmp->left);
                    if(tmp->right) q.push(tmp->right);
                }
                ans.push_back(path);
                path.clear();
            }
            return ans;
        }
    
};